package com.xxx.app.controller;


import com.xxx.app.manager.UserManager;
import com.xxx.domain.db.User;
import com.xxx.service.db.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserController {

    @Autowired
    UserManager userManager;

    /**
     * 保存用户
     * @param user
     * @return
     */
    @PostMapping("/user/save")
    public Long save(@RequestBody User user){

        return userManager.save(user);
    }

    @GetMapping("/user/findByMobile")
    public User findByMobile(String mobile){

        return userManager.findByMobile(mobile);
    }


    //发送验证码
    @PostMapping("/user/login")
    public void sendCode(@RequestBody Map<String,String> map){
        //1.获取手机号
        String phone = map.get("phone");
        //2.调用userManger中的方法实现操作
        userManager.sendCode(phone);
    }

    //注册登陆
    @PostMapping("/user/loginVerification")
    public ResponseEntity regAndLogin(@RequestBody Map<String,String> map){
        return userManager.regAndLogin(map);
    }
}
